/**
 * 
 */
package org.gpp.proj1.test;

import java.io.FileNotFoundException;

import org.gpp.proj1.robot.part.SparePart;
import org.gpp.proj1.robot.part.parser.InvalidPartFileException;
import org.gpp.proj1.robot.part.parser.PartFileParser;

import com.jme.math.Vector3f;
import com.jme.util.LoggingSystem;

import easyaccept.EasyAccept;

/**
 * 
 * @author Gustavo de Farias
 */
public class PartFacade {
	
	SparePart part;
	
	public PartFacade() {
		// Disabling logging
		LoggingSystem.getLoggingSystem().loggerOn( false );
	}
	
	public void loadPart(String file) throws FileNotFoundException, InvalidPartFileException {
		this.part = PartFileParser.parseFile( file );
	}
	
	public String getName() {
		return this.part.getName();
	}
	
	public String getPartType() {
		return this.part.getPartType().getName();
	}
	
	public int getPrice() {
		return this.part.getPrice();
	}
	
	public String getAttribute(String attrib) {
		return this.part.getAttribute(attrib);
	}
	
	public String getModelFile(String modelName) {
		return this.part.getModelFile(modelName);
	}
	
	public int getModifiersNumber() {
		return this.part.getModifiers().size();
	}
	
	public boolean containsAction(String actionName) {
		return this.part.getActions().contains(actionName);
	}
	
	public float getEmissorTranslation( String emissor, String parent, String coordinate) throws Exception {
		try {
			Vector3f translation = this.part.getEmissor(emissor).getEmissorNode(parent).getLocalTranslation();
			
			if (coordinate.equals("x")) {
				return translation.x;
			}
			else if (coordinate.equals("y")) {
				return translation.y;
			}
			else if (coordinate.equals("z")) {
				return translation.z;
			}
			else {
				throw new Exception();
			}
		}
		catch (Exception e) {
			throw new Exception("Invalid emissor, parent or coordinate.");
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		args = new String[]{"org.gpp.proj1.test.PartFacade", "test/part_test.txt"};
		EasyAccept.main(args);
	}
}